package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.HwWord;
import emulator.hardware.clock.ClockImplementation;
import emulator.hardware.memory.MemoryBlock;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.RTI;
import emulator.hardware.nmos6502.operands.NoOperand;

public class RTITest {

	@Test
	public void testExecute() throws EmulatorException {
		Cpu6502 cpu = new Cpu6502();
		MemoryBlock memory = new MemoryBlock(65536);
		ClockImplementation clock = new ClockImplementation();
		cpu.attach(memory, clock);
		cpu.setPC(0xFEDC);
		cpu.setSP(new HwByte(0xFC));
		memory.write(0x1FF, 0x1A);
		memory.write(0x1FE, 0x2A);
		Flags6502 flags = new Flags6502();
		flags.setCarry(true);
		flags.setZero(true);
		memory.write(0x1FD, (int) flags.getNumber());

		RTI rti = new RTI();
		rti.execute(cpu, new NoOperand());
		assertEquals(new HwByte(0xFF), cpu.getSP());
		assertEquals(new HwWord(0x1A2A), cpu.getPC());
		assertEquals(flags, cpu.getFlags());
	}
}
